package com.ithema.edu.info.manager.controller;

import com.ithema.edu.info.manager.domain.Student;
import com.ithema.edu.info.manager.service.StudentService;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentController extends BaseStudentController {
    private Scanner sc = new Scanner(System.in);
    private StudentService se=new StudentService();

    public void start() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("--------欢迎来到 <学生> 管理系统--------");
            System.out.println("请输入您的选择: 1.添加学生  2.删除学生  3.修改学生  4.查看学生  5.退出");
            int choose = scanner.nextInt();
            switch (choose) {
                case 1:
                    addStudents();  //添加学生
                    break;
                case 2:
                    deleteStudent();  //删除学生
                    break;
                case 3:
                    updateStudent();  //修改学生
                    break;
                case 4:
                    queryStudents();  //查看学生
                    break;
                case 5:
                    System.out.println("退出学生管理系统");
                    return;//将方法结束!!!!
                default:
                    System.out.println("您输入的有误！请重新输入！");
                    break;
            }
        }
    }

    public void queryStudents() {
        ArrayList<Student> List = se.queryStudents();
        if (List.size() == 0) {
            System.out.println("无数据！请添加后查看！");
        } else {
            System.out.println("学号" + "\t\t" + "姓名" + "\t" + "年龄" + "\t\t" + "手机号");
            for (int i = 0; i < List.size(); i++) {
                Student student = List.get(i);
                System.out.println(student.getId() + "\t" + student.getName() + "\t" + student.getAge() + "\t" + student.getPhone());
            }
        }

    }
}
